package com.atguigu.gulimall.order.vo;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 孤风雪影
 * @date 2021/1/21 18:21
 */
@Data
public class OrderConfirmVo {

    //收货地址: ums_member_receive_address
    private List<MemberAddressVo> addresses;

    //所有选中的购物项
    private List<OrderItemVo> selectOrderItems;

    //发票记录...

    //优惠券信息...
    private Integer integration;

    //订单总额
    private BigDecimal total;

    //应付价格
    private BigDecimal payPrice;

    //防重令牌
    private String orderToken;

    Map<Long, Boolean> stocks;


    public Integer getCount(){
        Integer sum = 0;
        if (!CollectionUtils.isEmpty(selectOrderItems)){
            for (OrderItemVo item : selectOrderItems) {
                sum += item.getCount();
            }
        }
        return sum;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(selectOrderItems)){
            for (OrderItemVo item : selectOrderItems) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }
        return sum;
    }

    //默认应付总额就是订单总额，此时并没有计算运费
    public BigDecimal getPayPrice() {
        return this.getTotal();
    }
}
